package com.it.App.controller;

import com.it.App.entity.SysUser;
import com.it.App.service.SysUserService;
import com.it.App.vo.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: CaoYouGen
 * @DateTime: 2023/11/22/12:16
 * @注释: TODO
 **/
@RestController
@RequestMapping("/sys")
@Api(tags = "用户相关接口")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("/getUser")
    @ApiOperation("根据用户名获取用户")
    @PreAuthorize("hasAuthority('sys:getUser')")
    public Response<?> getUserByName(String username){
        return sysUserService.getUserByName(username);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public Response<?> login(@RequestBody SysUser sysUser){
        return sysUserService.login(sysUser);
    }

    @GetMapping("/logout")
    @ApiOperation("用户登出")
    public Response<?> logout(){
        return sysUserService.logout();
    }


    @PostMapping("/user/save")
    @ApiOperation("添加用户")
    @PreAuthorize("hasAuthority('sys:role:save')")
    public Response<?> userSave(){
        return Response.ok("新增用户成功！");
    }

    @PostMapping("/user/update")
    @ApiOperation("修改用户")
    @PreAuthorize("hasAuthority('sys:role:update')")
    public Response<?> updateSave(){
        return Response.ok("更新用户成功！");
    }

    @GetMapping("/user/delete")
    @ApiOperation("删除用户")
    @PreAuthorize("hasAuthority('sys:role:delete')")
    public Response<?> deleteSave(){
        return Response.ok("删除用户成功！");
    }
}
